﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace IAD2
{
    class TrianglePoints : PointGenerator
    {
        public TrianglePoints(Neuron center, double height, int number)
        {
            Neuron randPoint;
            this.points = new List<Neuron>();
            Random random = new Random();
            Neuron pointA = new Neuron(center.X , (center.Y + (height/2)));
            Neuron pointB = new Neuron((center.X + (height / 2)), (center.Y - (height / 2)));
            Neuron pointC = new Neuron((center.X- (height / 2)), (center.Y - (height / 2)));
            double d1, d2, d3;
            for (int i = 0; i < number; i++)
            {

                do
                {
                    double x = (random.NextDouble() * 2 - 1) * height + center.X;
                    double y = (random.NextDouble() * 2 - 1) * height + center.Y;
                    randPoint = new Neuron(x, y);

                    d1 = randPoint.X * (pointA.Y - pointB.Y) + randPoint.Y * (pointB.X - pointA.X) + (pointA.X * pointB.Y - pointA.Y * pointB.X);
                    d2 = randPoint.X * (pointB.Y - pointC.Y) + randPoint.Y * (pointC.X - pointB.X) + (pointB.X * pointC.Y - pointB.Y * pointC.X);
                    d3 = randPoint.X * (pointC.Y - pointA.Y) + randPoint.Y * (pointA.X - pointC.X) + (pointC.X * pointA.Y - pointC.Y * pointA.X);  
                  
                } while (!((d1 <= 0) && (d2 <= 0) && (d3 <= 0) || (d1 >= 0) && (d2 >= 0) && (d3 >= 0)));
                this.points.Add(randPoint);

            }
             
        }
    }
}
